package cn.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;

import cn.kpi.entity.civilass.CATempDetailEntity;
import cn.kpi.service.civilass.ICivilAssKpService;

@Controller
@RequestMapping("civilasskp")
public class CivilAssKpController {
	
	@Autowired
	private ICivilAssKpService iCivilAssKpService;

	@RequestMapping("/civilass_kp_list")
	public String CivilAssKpList(Model model) {
		return "civilass/civilass_kp_list";
	}
	
	@RequestMapping("/civilass_kp_edit")
	public String CivilAssKpEdit(Model model) {
		try{
			List<CATempDetailEntity> lstdetail = iCivilAssKpService.GetItemListByStatus();
			String columns="";
			
			for(int i=0;i<lstdetail.size();i++){
				columns+="MAX(CASE WHEN itemname='"+lstdetail.get(i).getItemname()+"' THEN score ELSE 0 END) AS '"+lstdetail.get(i).getItemname()+"',";
			}
			columns=columns.substring(0,columns.length()-1);
			
			List<Map> lstorg=iCivilAssKpService.GetTempOrgListByTempId(lstdetail.get(0).getTempid(), columns);
			

			System.out.println(JSON.toJSONString(lstorg));
			
			model.addAttribute("titleh", lstdetail);
			model.addAttribute("databody", lstorg);
		}
		catch(Exception ex){
			
		}
		return "civilass/civilass_kp_edit";
	}
	
	
}
